package com.zrj.gulimall.product.web;

import com.zrj.gulimall.product.entity.CategoryEntity;
import com.zrj.gulimall.product.service.CategoryService;
import com.zrj.gulimall.product.vo.Catelog2Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @author zhaorujie
 * @version 1.0
 * @Description
 * @date 2021/1/28 14:53
 */
@Controller
public class IndexController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping(value = {"/", "index.html"})
    public String indexPage(Model model){
        //1、查出所有的一级分类
        List<CategoryEntity> entityList = categoryService.getLevel1Categorys();
        model.addAttribute("categories", entityList);
        return "index";
    }


    @GetMapping(value = "/index/catalog.json")
    @ResponseBody
    public Map<String, List<Catelog2Vo>> getCatalogJson(){
        return categoryService.getCatalogJson();
    }
}
